﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using UnityEngine;

namespace EvaOxygen
{
    //This uses weak references to ensure partModule only gets added once per KerbalEVA
    public class EvaController
    {
        private static Dictionary<WeakReference<PartModule>, EvaController> controllers = new Dictionary<WeakReference<PartModule>, EvaController>();

        public static bool GetInstance(PartModule partmodule)
        {
            foreach (var kvp in controllers.ToArray())
            {
                var wr = kvp.Key;
                var v = wr.Target;
                if (v == null)
                {
                    controllers.Remove(wr);
                }
                else if (v == partmodule)
                {
                    return false;
                }
            }

            var commander = new EvaController();
            controllers[new WeakReference<PartModule>(partmodule)] = commander;
            return true;
        }

        public EvaController()
        {
        }
    }
}
